import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sports_new/entity/expert/zq_hot_expert_entity.dart';
import 'package:sports_new/utils/utils.dart';
import 'package:sports_new/view/expert/items/expert_logo.dart';

import '../../../resources/colours.dart';
import '../../../utils/mode_config.dart';
import '../../../utils/routes.dart';
import '../../../widgets/gif.dart';
import '../../../widgets/base/qkd_text.dart';
import '../../pick/items/expert_record_tag.dart';

class HotExpertItem extends StatelessWidget {
  const HotExpertItem({
    super.key,
    required this.entity,
    required this.sportsId,
    this.eventType,
  });

  final HotExpertEntity? entity;
  final int sportsId;
  final String? eventType;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if(eventType != null) {
          Utils.onEvent(
            eventType!,
            params: {eventType!: entity?.expertId}
          );
        }
        // String index = "quanbu";
        // if(sportsId == 1){
        //   index = "zq";
        // }else if(sportsId == 2){
        //   index = "lq";
        // }
        // Get.toNamed(
        //   Routes.userPage,
        //   arguments: entity?.expertId,
        //   parameters: {'type': '2','index':index}
        // );
        if(entity?.liveInfo?.liveId.hasValue??false){
          if(entity?.liveInfo?.bindMatch == 1) {
            Get.toNamed(
                entity?.liveInfo?.liveSportsId == 1 ?
                Routes.zqMatchDetail : Routes.lqMatchDetail,
                arguments: entity?.liveInfo?.matchId,
                parameters: {"roomId": "${entity?.liveInfo?.liveId}"}
            );
          }else{
            Get.toNamed(
              Routes.liveNormal,
              arguments: entity?.liveInfo?.liveId
            );
          }
        }else {
          String index = "quanbu";
          if(sportsId == 1){
            index = "zq";
          }else if(sportsId == 2){
            index = "lq";
          }
          Get.toNamed(Routes.userPage,
              arguments: entity?.expertId, parameters: {'type': '2','index':index});
        }
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          ExpertLogo(
            logo: entity?.logo,
            inLive: entity?.liveInfo?.liveId.hasValue == true,
            hasAuth: entity?.isInvite == 1,
            size: 40,
            planCnt: entity?.viewCnt,
          ),
          const SizedBox(height: 4, width: 10),
          QkdText(
            entity?.name ?? '',
            fontSize: 12, fontWeight: FontWeight.w500,
            maxLines: 1,
          ),
          if(ModeConfig.expertRecord)...[
            const SizedBox(height: 3, width: 10),
            ExpertRecordTag(
              text: "${entity?.value}",
              type: 6, textSize: 11,fontWeight: FontWeight.w500,
            )
          ]
        ],
      ),
    );
  }
}
